// 鼠标点击坐标
var mousePos_x ;
var mousePos_y ;

// 鼠标点击事件
function mousePosition(ev){ 
	if(ev.pageX || ev.pageY){ 
		return {x:ev.pageX, y:ev.pageY}; 
	} return { 
		x:ev.clientX + document.body.scrollLeft - document.body.clientLeft, 
		y:ev.clientY + document.body.scrollTop - document.body.clientTop 
	}; 
} 
function mouseDown(ev){ 
	ev = ev || window.event; 
	var mousePos = mousePosition(ev);
	mousePos_x = mousePos.x;
	mousePos_y = mousePos.y;
} 

// 配置时间选择格式 id:元素ID value:默认值
function configDate(id, value, format){
	$( "#"+id ).datepicker();
	$( "#"+id ).datepicker( "option", "dateFormat", format);
	$( "#"+id ).datepicker( "option", "changeYear", true );
	$( "#"+id ).datepicker( "option", "changeMonth", true );
	$( "#"+id ).datepicker( "option", "currentText", 'Now' );
	$( "#"+id ).datepicker( "option", "gotoCurrent", true );
	$( "#"+id ).datepicker( "option", "showButtonPanel", true );
	$( "#"+id ).datepicker( "option", "dayNames", ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'] );
	$( "#"+id ).datepicker( "option", "dayNamesMin", ['日', '一', '二', '三', '四', '五', '六'] );
  	$( "#"+id ).datepicker( "option", "dayNamesShort", ['日', '一', '二', '三', '四', '五', '六'] );
	$( "#"+id ).datepicker( "option", "monthNames", ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'] );
	$( "#"+id ).datepicker( "option", "monthNamesShort", ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'] );
	// 默认值
	$( "#"+id ).val(value);
}

// 将所有账户信息的添加到页面select元素中
function getAllAccount2Element(id, accountId){
	$.ajax({
	    url: 'accountAction.do?method=getAccount4Ajax',
	    type: 'GET',
	    dataType: 'json',
	    cache: false,
	    error: function(){
	        alert('获取账户信息出错!');
	    },
	    success: function(json){
	    	$.each(json, function(i, obj){
				$('#'+id).append("<option value='" + obj.accountId + "'" + (accountId==obj.accountId?'selected':'') + ">" + obj.accountName + "</option>");
			});
	    }
	});
}

/** 精确计算函数,提供float精准计算 **/
// 减法运算
function accSub(arg1,arg2){
	var r1,r2,m,n;
 	try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0}
 	try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0}
 	m=Math.pow(10,Math.max(r1,r2));
 	//last modify by deeka
 	//动态控制精度长度
 	n=(r1>=r2)?r1:r2;
 	return ((arg1*m-arg2*m)/m).toFixed(n);
}

// 加法运算
function accAdd(arg1,arg2){ 
	var r1,r2,m; 
	try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0} 
	try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0} 
	m=Math.pow(10,Math.max(r1,r2)) 
	return (arg1*m+arg2*m)/m 
} 

// 乘法运算
function accMul(arg1,arg2) {
	var m=0,s1=arg1.toString(),s2=arg2.toString();
	try{m+=s1.split(".")[1].length}catch(e){}
	try{m+=s2.split(".")[1].length}catch(e){}
	return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m) 
}

// 除法运算
function accDiv(arg1, arg2){
	var t1 = 0, t2 = 0, r1, r2;
	try {
		t1 = arg1.toString().split(".")[1].length
	} 
	catch (e) {
	}
	try {
		t2 = arg2.toString().split(".")[1].length
	} 
	catch (e) {
	}
	with (Math) {
		r1 = Number(arg1.toString().replace(".", ""))
		r2 = Number(arg2.toString().replace(".", ""))
		return (r1 / r2) * pow(10, t2 - t1);
	}
}
// 扩展String的endWith方法
String.prototype.endWith=function(str){
  if(str==null||str==""||this.length==0||str.length>this.length)
    return false;
  if(this.substring(this.length-str.length)==str)
    return true;
  else
    return false;
  return true;
}
// 扩展String的startWith方法
String.prototype.startWith=function(str){
  if(str==null||str==""||this.length==0||str.length>this.length)
    return false;
  if(this.substr(0,str.length)==str)
    return true;
  else
    return false;
  return true;
}

$(document).ready(function(){
	// 过滤掉单元格的内容,截取掉.0
	$.each($("td"), function(){
		var tdHtml = $(this).html();
		if(tdHtml.endWith('.0')){
			$(this).html(tdHtml.substring(0,tdHtml.length-2));
		}
	});
	// 过滤掉input的内容,截取掉.0
	$.each($("input:text"), function(){
		var ipt = $(this).val();
		if(ipt.endWith('.0')){
			$(this).val(ipt.substring(0,ipt.length-2));
		}
	});
})



